package com.shelpe.services.sinbad.entity.dto;

import org.apache.commons.lang.StringUtils;

import com.shelpe.services.sinbad.entity.enums.EnitityEnumable;

import lombok.Data;

@Data
public class EnumPair {

	private String value;
	private String description;
	
	public EnumPair(){}
	public EnumPair(String value){
		this.value = value;
	}
	
	public EnumPair(String v, String desc){
		this(v);
		this.description = desc;
	}
	
	public <T extends Enum<T>> T to(Class<T> enumType){
		T en = null;
		if(StringUtils.isNotBlank(this.value)){
			try{
				en = Enum.valueOf(enumType, this.value);
			}catch(IllegalArgumentException ex){
				
			}
		}
		return en;
	}
	
	public static EnumPair from(EnitityEnumable en){
		EnumPair ep = new EnumPair();
		ep.setDescription(en.description());
		ep.setValue(en.name());
		return ep;
	}
}
